package firstcontent.reference;

import java.lang.ref.WeakReference;

/**
 * @Author: fxy
 * @Date: 2022/02/25/9:20
 * @Description:
 */
public class WeakReferenceTest {
    public static class User{
        public int id;
        public String name;
        public byte[] bytes;
        public User(int id,String name,int size){
            this.id = id;
            this.name = name;
            bytes = new byte[size];
        }

        @Override
        public String toString() {
            return "User{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    '}';
        }
    }

    public static void main(String[] args) {
        WeakReference<SoftReferenceTest.User> userSoftRef = new WeakReference<>(new SoftReferenceTest.User(1,"yun",5*1024*1024));
        System.out.println(userSoftRef.get());
        System.gc();
        System.out.println(userSoftRef.get());

    }
}
